#include "cpu/exec/template-start.h"

#define instr push

make_helper(concat(push_r_, SUFFIX)) {
    int reg = ops_decoded.opcode & 0x7;   
    reg_l(R_ESP) -= 4;
    MEM_W(reg_l(R_ESP), REG(reg));
    print_asm("push %%%s", regsl[reg]);
    return 1;
}

/* push imm (0x68 / 0x6a) */
make_helper(concat(push_i_, SUFFIX)) {
    DATA_TYPE imm = instr_fetch(eip + 1, DATA_BYTE);
#if DATA_BYTE == 1
    imm = (int32_t)(int8_t)imm;   
#else
    imm = (int32_t)imm;         
#endif
    reg_l(R_ESP) -= 4;
    MEM_W(reg_l(R_ESP), imm);
    print_asm("push $0x%x", imm);
    return 1 + DATA_BYTE;
}

make_helper(concat(push_rm_, SUFFIX)) {
    int len = concat(decode_rm_, SUFFIX)(eip + 1);
    reg_l(R_ESP) -= 4;
    MEM_W(reg_l(R_ESP), op_src->val);
    print_asm("push %s", op_src->str);
    return len + 1;
}

#include "cpu/exec/template-end.h"
